package org.wgstest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.wgsframework.MiniMongodb;

public class TestMiniMogodb {
	
	private static final String uuid  = "3fc77a5c-1300-438d-aa0d-419924ae47bf";
	private static final String database_name  = "mini-mongodb.xml";
	
	
	public static void main(String[] args) {
		//new TestMiniMogodb().createDatabse();//创建数据库
		//new TestMiniMogodb().createTable("wgsTest");
		new TestMiniMogodb().insertData();//插入数据
		//new TestMiniMogodb().updateData();//修改数据
		//new TestMiniMogodb().listAll();//列表数据
		//new TestMiniMogodb().deleteData();//删除数据
		//new TestMiniMogodb().listAllByParas();

	}
	
	/**
	 * 创建数据库（默认名称和路径）
	 */
	public void createDatabse(){
		try {
			MiniMongodb dao = new MiniMongodb();
			dao.createDataBase(database_name);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 创建数据库表
	 * @param tableName  表名
	 */
	public void createTable(String tableName){
		try {
			MiniMongodb dao = new MiniMongodb();
			dao.createTable(database_name, tableName);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	
	/**
	 * 插入数据
	 */
	public void insertData(){
		SysUser sysUser = new SysUser();
		sysUser.setName("wuguosuan44");
		sysUser.setAge(32);
		sysUser.setSex("男");
		sysUser.setMobile("13556565557");
		
		SysUserSub sub = new SysUserSub();
		sub.setSubName("吴语涵");
		sub.setWorkNum("121212");
		sysUser.setSysUserSub(sub);
		try {
			MiniMongodb dao = new MiniMongodb();
			dao.addData(database_name,"wgsTest",sysUser);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 修改数据
	 */
	public void updateData(){
		SysUser sysUser = new SysUser();
		sysUser.set_uuid(uuid);
		sysUser.setName("吴国算修改");
		sysUser.setAge(28);
		try {
			MiniMongodb dao = new MiniMongodb();
			dao.updateData(database_name,"wgsTest",sysUser);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	/**
	 * 删除数据
	 */
	public void deleteData(){
		SysUser sysUser = new SysUser();
		sysUser.set_uuid(uuid);
		try {
			MiniMongodb dao = new MiniMongodb();
			dao.deleteData(database_name,"wgsTest",sysUser);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 获取表中所有数据
	 */
	public void listAll(){
		try {
			MiniMongodb dao = new MiniMongodb();
			List<Map> list = dao.loadTableDatas(database_name,"wgsTest");
			System.out.println(list.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 根据参数获取表中的数据
	 */
	public void listAllByParas(){
		try {
			Map<String,Object> paras = new HashMap<String,Object>();
			paras.put("age", 31.0);
			MiniMongodb dao = new MiniMongodb();
			List<Map> list = dao.loadTableDatasByParas(database_name,"wgsTest",paras);
			System.out.println(list.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
